home *** CD-ROM | disk | FTP | other *** search
/ PD Collection CD 1 / PD Collection CD 1.iso / programer2 / icon / Docs / Tr90-4 < prev    next >
Text File  |  1990-07-19  |  61KB  |  2,377 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.               Variant Translators for Version 8 of
  15.                               Icon*
  16.  
  17.  
  18.                         Ralph E. Griswold
  19.                          Kenneth Walker
  20.  
  21.  
  22.  
  23.                             TR 90-4a
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.          January 1, 1990; last revised February 17, 1990
  50.  
  51.  
  52.                  Department of Computer Science
  53.  
  54.                     The University of Arizona
  55.  
  56.                       Tucson, Arizona 85721
  57.  
  58.  
  59.  
  60.  
  61. *This work was supported by the National Science Foundation under
  62. Grants CCR-8713690 and CCR-8901573.
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.               Variant Translators for Version 8 of
  77.                               Icon
  78.  
  79.  
  80.  
  81.  
  82. 1.__Introduction
  83.  
  84.    A preprocessor, which translates text from source language A
  85. to source language B,
  86.  
  87.         A -> B
  88.  
  89. is a popular and effective means of implementing A, given an
  90. implementation of B.  B is referred to as the target language.
  91. Ratfor [1] is perhaps the best known and most widely used example
  92. of this technique, although there are many others.
  93.  
  94.    In some cases A is a variant of B.  An example is Cg [2], a
  95. variant of C that includes a generator facility similar to Icon's
  96. [3].  Cg consists of C and some additional syntax that a prepro-
  97. cessor translates into standard C. A run-time system provides the
  98. necessary semantic support for generators. Note that the Cg
  99. preprocessor is a source-to-source translator:
  100.  
  101.         Cg -> C
  102.  
  103. where Cg differs from C only in the addition of a few syntactic
  104. constructs.  This can be viewed as an instance of a more general
  105. paradigm:
  106.  
  107.         A+ -> A
  108.  
  109.  
  110.    The term ``translator'' is used here in the general sense, and
  111. includes both source-to-source translators, such as preproces-
  112. sors, and source-to-object translators, such as compilers.  In
  113. practice, the application of a source-to-source translator
  114. (preprocessor) may be followed by the application of a source-
  115. to-object translator (compiler). The combination is, of course,
  116. also a translator.
  117.  
  118.    The term ``variant translator'' is used here to refer to a
  119. translator that differs in its action, in some respect, from a
  120. standard one for a language. The applications described in this
  121. report relate to source-to-source translators, although the term
  122. ``preprocessor'' is too restrictive to describe all of them.
  123.  
  124.    There are many uses for variant translators. Some of them are:
  125.  
  126.  
  127.  
  128.  
  129.  
  130.                               - 1 -
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.      + the addition of syntactic constructions to produce a
  140.        superset of a language, as in the case of Cg
  141.  
  142.      + the deletion of features in order to subset a language
  143.  
  144.      + the translation of one source language into another [4]
  145.  
  146.      + the addition of monitoring code, written in the target
  147.        language
  148.  
  149.      + the insertion of termination code to output monitoring
  150.        data
  151.  
  152.      + the insertion of initialization code to incorporate addi-
  153.        tional run-time facilities
  154.  
  155.      + the insertion of code for debugging and checking purposes
  156.        [5,6]
  157.  
  158. Note that in several cases, the translations can be characterized
  159. by
  160.  
  161.         A -> A
  162.  
  163. The input text and the output text may be different, but they are
  164. both in A.  Both the input and the output of the variant transla-
  165. tor can be processed by a standard translator for the target
  166. language A.
  167.  
  168.    One way to implement a variant translator is to modify a stan-
  169. dard source-to-object translator, avoiding the preprocessor. This
  170. approach may or may not be easy, depending on the translator. In
  171. general, it involves modifying the code generator, which often is
  172. tricky and error prone. Furthermore, if the variant is an experi-
  173. ment, the effort involved may be prohibitive.
  174.  
  175.    The standard way to produce a variant translator is the one
  176. that is most often used for preprocessors in general, including
  177. ones that do not fit the variant translator paradigm - writing a
  178. stand-alone program in any convenient language. In the case of
  179. Ratfor, the preprocessor is written in Ratfor, providing the
  180. advantages of bootstrapping.
  181.  
  182.    This approach presents several problems. In the first place,
  183. writing a complete, efficient, and correct preprocessor is a sub-
  184. stantial undertaking. In experimental work, this effort may be
  185. unwarranted, and it is common to write the preprocessor in a
  186. high-level language, handling only the variant portion of the
  187. syntax, leaving the detection of errors to the final translator.
  188. Such preprocessors have the virtue of being easy to produce, but
  189. they often are slow, frequently unfaithful to the source
  190. language, and the failure to parse the input language completely
  191. may lead to mysterious results when errors are detected, out of
  192. context, by the final translator.
  193.  
  194.  
  195.  
  196.                               - 2 -
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.    Modern tools such as Lex [7] and Yacc [8], that operate on
  206. grammatical specifications, have made the production of compilers
  207. (and hence translators in general) comparatively easy and have
  208. removed many of the sources of error that are commonly found in
  209. hand-tailored translators. Nonetheless, the construction of a
  210. translator for a large and complicated language is still a sub-
  211. stantial undertaking.
  212.  
  213.    If, however, a translator already exists for a language that
  214. is based on the use of such tools, it may be easy to produce a
  215. variant translator that is efficient and demonstrably correct by
  216. modifying grammatical specifications.  The key is the use of
  217. these tools to produce a source-to-source translator, rather than
  218. producing a source-to-object translator.  This technique was used
  219. in Cg. An existing Yacc specification for the C compiler was
  220. modified to generate C source code instead of object code. The
  221. idea is a simple one, but it has considerable utility and can be
  222. applied to a wide range of situations.
  223.  
  224.    This report describes a system that uses this approach for the
  225. construction of variant translators for Icon.  This system
  226. presently runs only under UNIX systems with a large amount of
  227. memory.  The reader should have a general knowledge of Icon,
  228. Yacc, C, and UNIX.
  229.  
  230.  
  231. 2.__Overview_of_Variant_Translators_for_Icon
  232.  
  233.    The heart of the system for constructing variant translators
  234. for Icon consists of an ``identity translator''.  The output of
  235. this identity translator differs from its input only in the
  236. arrangement of nonsemantic ``white space'' and in the insertion
  237. of semicolons between expressions, which are optional in some
  238. places in Icon programs.
  239.  
  240.    The identity translator uses the same Yacc grammar as the reg-
  241. ular Icon translator, but uses different semantic actions. These
  242. semantic actions are cast as macro definitions in the grammar,
  243. which are expanded before the grammar is translated by Yacc into
  244. a parser. One set of macros is supplied for the regular Icon
  245. translator and another set is supplied for the identity transla-
  246. tor.  The macros used by the identity translator echo the input
  247. text, producing source-code output. In addition to the grammar,
  248. other code is shared between the two translators, insuring a high
  249. degree of consistency between the two systems.
  250.  
  251.    A variant translator is created by first creating an identity
  252. translator and then modifying it. There is a shell script for
  253. producing identity translators and associated support software to
  254. simply the process of making modifications.  This support
  255. software allows macro definitions to be changed via specification
  256. files, minimizing the clerical work needed to vary the format of
  257. the output. There also is a provision for including user func-
  258. tions in the parser, so that more complicated operations can be
  259.  
  260.  
  261.  
  262.                               - 3 -
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271. written in C. Finally, the grammar for the identity translator
  272. can be modified in order to make structural changes in the syn-
  273. tax.
  274.  
  275.    The following sections describe this system in more detail and
  276. include a number of examples of its use.
  277.  
  278.  
  279. 3.__The_Grammar_for_the_Icon_Identity_Translator
  280.  
  281.    The Icon grammar is listed in Appendix A. Many variant trans-
  282. lators can be constructed without modifying this grammar, and
  283. minor modifications can be made to it without a detailed
  284. knowledge of its structure. Knowledge of a few aspects of this
  285. grammar are important, however, to understanding the translation
  286. process.
  287.  
  288.    There are two types of semantic actions. The semantic action
  289. for a declaration outputs text. The semantic action for a com-
  290. ponent of a declaration, such as an identifier list or an expres-
  291. sion, assigns a string to the Yacc attribute for the component.
  292. Declarations are parsed by the production:
  293.  
  294.         decl    : record {Recdcl($1);} ;
  295.                 | proc {Procdcl($1);} ;
  296.                 | global {Globdcl($1);} ;
  297.                 | link {Linkdcl($1);} ;
  298.  
  299. The non-terminals record, proc, global, and link each produce a
  300. string and the corresponding macro Recdcl, Procdcl, Globdcl, or
  301. Linkdcl prints the string.
  302.  
  303.    Because the grammar is used for both the regular Icon transla-
  304. tor and the variant translator system, the macro calls must be
  305. more general than what is required for either one alone. Consider
  306. the production for global:
  307.  
  308.         global  : GLOBAL {Global0($1);} idlist  {Global1($1, $2, $3);} ;
  309.  
  310. The macro Global0 is needed in the regular translator, but per-
  311. forms no operation in the identity translator. The macro Global1
  312. does the work in the identity translator; it concatenates "global
  313. " with the string produced by idlist, and this new string becomes
  314. the result of this production. The macro Global1 is passed $1,
  315. $2, and $3 even though it only uses $3. This is done for general-
  316. ity.
  317.  
  318.    The rules and the definitions that construct and output
  319. strings are provided as part of the identity translator. When a
  320. variant translator is constructed, changes are necessary only in
  321. situations in which the input is not to be echoed in the output.
  322.  
  323.    Deletions from the standard syntax can be accomplished by
  324. changing macro definitions to produce error messages instead of
  325.  
  326.  
  327.  
  328.                               - 4 -
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337. output text. It is generally better, however, to delete rules
  338. from the grammar, so that all syntactic errors in the input are
  339. handled in the same way, by Yacc.
  340.  
  341.    Modifications and additions to the standard grammar require a
  342. more thorough understanding of the structure of the grammar.
  343.  
  344.  
  345. 4.__Macro_Definitions
  346.  
  347.    The purpose of using macro calls in the semantic actions of
  348. the grammar is to separate the structure of the grammar from the
  349. format of the output and to allow the output format to be speci-
  350. fied without modification of the grammar.
  351.  
  352.    The macro definitions for declarations are all the same. For
  353. example the definition of Global for the identity translator is:
  354.  
  355.         #define Globdcl(x)if (!nocode) treeprt(x); treeinit()
  356.  
  357. The variable nocode is set when an error is detected during pars-
  358. ing.  This helps prevent the variant translator from generating a
  359. program with syntax errors. The reason for doing this is that the
  360. output of a variant translator is usually piped directly into the
  361. regular Icon translator. If syntax errors were propagated, two
  362. error messages would result: one from the variant translator and
  363. one from the Icon translator. The message from the variant trans-
  364. lator is the one that is wanted because it references the line
  365. number of the original source whereas the message from the Icon
  366. translator references the line number of the generated source.
  367.  
  368.    The function treeprt prints a string and the function treeinit
  369. reclaims storage. See the Section 5 for details of string
  370. representation.
  371.  
  372. 4.1__Specifications_for_Macros
  373.  
  374.    The macro definitions for expressions produce strings, gen-
  375. erally resulting from the concatenation of strings produced by
  376. other rules.  In order to simplify the definition of macros, a
  377. specification format is provided.  Specifications are processed
  378. by a program that produces the actual definitions.  For example,
  379. the macro While1 is used in the rule
  380.  
  381.         WHILE expr DO expr {While1($1,$2,$3,$4);} ;
  382.  
  383. A specification for this macro to produce an identity translation
  384. is:
  385.  
  386.         While1(w,x,y,z)     "while " x        " do "   z
  387.  
  388. Tabs separate the components of the specification. The first com-
  389. ponent is the prototype for the macro call, which may include
  390. optional arguments enclosed in parentheses as illustrated by the
  391.  
  392.  
  393.  
  394.                               - 5 -
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403. example above. The remaining components are the strings to be
  404. concatenated with the result being assigned to the Yacc pseudo-
  405. variable $$.
  406.  
  407.    Specification lines that begin with # or which are empty are
  408. treated as comments.  A set of lines delineated by %{ and %} are
  409. copied unchanged.  The ``braces'' %{ and %} must each occur alone
  410. on a separate line; these two delimiting lines are not copied.
  411. This feature allows the inclusion of actual macro definitions, as
  412. opposed to specifications, and the inclusion of C definitions.
  413. The standard macro definitions supplied for the identity transla-
  414. tor include examples of these features. These definitions are
  415. listed in Appendix B.
  416.  
  417.    Definitions can be changed by modifying the standard ones or
  418. by adding new definitions. In the case of duplicate definitions,
  419. the last one holds.  Definitions can be provided in several
  420. files, so variant definitions can be provided in a separate file
  421. that is processed after the standard definitions. See Sec. 8.
  422.  
  423.    Definitions can be deleted by providing a specification that
  424. consists only of a prototype for the call. For example, the
  425. specification
  426.  
  427.         While1()
  428.  
  429. deletes the definition for While1. This is a convenient way to
  430. insure a macro is undefined. It is usually used along with the
  431. copy feature to introduce macro definitions that cannot be gen-
  432. erated by the specification system.  For example, the following
  433. specifications eliminate reclamation of storage, preserving
  434. strings between declarations.
  435.  
  436.         Globdcl()
  437.         Linkdcl()
  438.         Procdcl()
  439.         Recdcl()
  440.         %{
  441.         #define Globdcl(x)if (!nocode) treeprt(x);
  442.         #define Linkdcl(x)if (!nocode) treeprt(x);
  443.         #define Procdcl(x)if (!nocode) treeprt(x);
  444.         #define Recdcl(x)if (!nocode) treeprt(x);
  445.         %}
  446.  
  447.  
  448. 4.2__Macros_for_Icon_Operators
  449.  
  450.    As shown in Appendix A, there is a distinct macro name for
  451. each Icon operator.  For example, Blim(x,y,z) is the macro for a
  452. limitation expression,
  453.  
  454.         expr1 \ expr2
  455.  
  456. Note that the parameter y is the operator symbol itself.  To
  457.  
  458.  
  459.  
  460.                               - 6 -
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468.  
  469. avoid having to know the names of the macros for the operators,
  470. specifications allow the use of operator symbols in prototypes.
  471. The symbols are automatically replaced by the appropriate names.
  472. Thus
  473.  
  474.         \(x,y,z)
  475.  
  476. can be used in a specification in place of
  477.  
  478.         Blim(x,y,z)
  479.  
  480. Unary operators are similar. For example, Uqmark(x,y), which is
  481. the macro for ?expr, can be specified as ?(x,y). In this case the
  482. parameter x is the operator symbol.
  483.  
  484.    In most cases, all operators of the same kind are translated
  485. in the same way. Since Icon has many operators, a generic form of
  486. specification is provided to allow the definition of all opera-
  487. tors in a category to be given by a single specification. In a
  488. specification, a string of the form <type> indicates a category
  489. of operators. The categories are:
  490.  
  491.         <uop>   unary operators, except as follows
  492.         <ucs>   control structures in unary operator format
  493.         <bop>   binary operators, except as follows
  494.         <aop>   assignment operators
  495.         <bcs>   control structures in binary operator format
  496.  
  497. The category <ucs> consists only of |.  The category <bcs> con-
  498. sists of ?, |, !, and \.
  499.  
  500.    For example, the specification for binary operators for iden-
  501. tity translations is
  502.  
  503.         <bop>(x,y,z)        x        " <bop> "         z
  504.  
  505. This specification results in the definition for every binary
  506. operator: +(x,y,z), -(x,y,z), and so on. In such a specification,
  507. every occurrence of <bop> is replaced by the corresponding opera-
  508. tor symbol. Note that blanks are necessary to separate the binary
  509. operator from its operands. Otherwise,
  510.  
  511.         i * *s
  512.  
  513. would be translated into
  514.  
  515.         i**s
  516.  
  517. which is equivalent to
  518.  
  519.         i ** s
  520.  
  521.  
  522.    The division of operators into categories is based on their
  523.  
  524.  
  525.  
  526.                               - 7 -
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535. semantic properties. For example, a preprocessor may translate
  536. all unary operators in the same way, but translate the repeated
  537. alternation control structure into a programmer-defined control
  538. operation [9].
  539.  
  540.  
  541. 5.__String_Handling
  542.  
  543.    Strings are represented as binary trees in which the leaves
  544. contain pointers to C strings. The building of these trees can be
  545. thought of as doing string concatenation using lazy evaluation.
  546. The concatenation operation just creates a new root node with its
  547. two operands as subtrees.  The real concatenation is only done
  548. when the strings are written out. Another view of this is that
  549. concatenation builds a list of strings with the list implemented
  550. as a binary tree. This view allows ``strings'' to be treated as a
  551. list of tokens. This approach is useful in more complicated
  552. situations where there is a need to distinguish more than just
  553. syntactic structures. For example, the head of the main procedure
  554. can be distinguished from the heads of other procedures by look-
  555. ing at the second string in the list for the procedure declara-
  556. tion.
  557.  
  558.    Strings come from three sources during translation: strings
  559. produced by the lexical analyzer, literal strings, and strings
  560. produced by semantic actions. The lexical analyzer produces
  561. nodes.  The cases where the nodes that are produced by the lexi-
  562. cal analyzer are of interest occur where strings are recognized
  563. for identifiers and literals - the tokens IDENT, STRINGLIT,
  564. INTLIT, REALIT, and CSETLIT.  These nodes contain pointers to the
  565. strings recognized. (The actual strings are stored in a string
  566. space and remain there throughout execution of the translator.)
  567. These nodes can be used directly as a tree (of one node) of
  568. strings. Other nodes produced by the lexical analyzer, for exam-
  569. ple those for operators, do not contain strings. However, all of
  570. these nodes contain line and column numbers referring to the
  571. location of the token in the source text. This line and column
  572. information can be useful in variant translators that need to
  573. produce output that contains position information from the input.
  574.  
  575.    A literal string must be coerced into a tree of one node.
  576. This is done with the C function
  577.  
  578.         q(s)
  579.  
  580. This is handled automatically when macros are produced from
  581. specifications.  For example, the specification
  582.  
  583.         Fail(x) "fail"
  584.  
  585. is translated into the macro
  586.  
  587.         #define Fail(x) $$ = q("fail")
  588.  
  589.  
  590.  
  591.  
  592.                               - 8 -
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600.  
  601.    Most semantic actions concatenate two or more strings and pro-
  602. duce a string.  They use the C function
  603.  
  604.         cat(n, t1,t2, ...,tn)
  605.  
  606. which takes a variable number of arguments and returns a pointer
  607. to the concatenated result. The first argument is the number of
  608. strings to be concatenated. The other arguments are the strings
  609. in tree format. The result is also in tree format.
  610.  
  611.    As an example, the specification
  612.  
  613.         While1(w,x,y,z)     "while " x        " do "   z
  614.  
  615. produces the definition
  616.  
  617.         #define While1(w,x,y,z) $$ = cat(4,q("while "),x,q(" do "),z)
  618.  
  619.  
  620.    Another function, item(t, n), returns the nth node in the
  621. ``list'' t.  For example, the name of a procedure is contained in
  622. the second node in the list for the procedure declaration (see
  623. Appendix A). Thus, if the procedure heading list is the value of
  624. head, item(head, 2) produces the procedure name.
  625.  
  626.    There are three macros that produce values associated with a
  627. node.  Str0() produces the string. For example, code conditional
  628. on the main procedure could be written as follows:
  629.  
  630.         if (strcmp(Str0(item(head,2)),"main") == 0) {
  631.                   .
  632.                   .
  633.                   .
  634.            }
  635.  
  636.  
  637.    As this example illustrates, semantic actions may be too com-
  638. plicated to be represented conveniently by macros. In such cases
  639. parser functions can be used. A file is provided for such func-
  640. tions. See Section 10 for an example.
  641.  
  642.    The macros Line and Col produce the source-file line number
  643. and column, respectively, of the place where the text for the
  644. node begins. The use of these attributes is illustrated in Sec-
  645. tion 10.
  646.  
  647.    In some sophisticated applications, variant translators may
  648. need other capabilities that are available in the translator sys-
  649. tem. For example, if a function produces a string, it may be
  650. necessary place this string in a place that survives the function
  651. call.  The Icon translator has a string allocation facility that
  652. can be used for this purpose: the free space begins at strfree
  653. and putident(n) installs a string of length n there. The use of
  654. such facilities requires more knowledge of the translator system
  655.  
  656.  
  657.  
  658.                               - 9 -
  659.  
  660.  
  661.  
  662.  
  663.  
  664.  
  665.  
  666.  
  667. than it is practical to provide here. Persons with special needs
  668. should study the translator in more detail.
  669.  
  670.  
  671. 6.__Modifying_Lexical_Components_of_the_Translator
  672.  
  673.    The lexical analyzer for Icon is written in C rather than in
  674. Lex in order to make it easier to perform semicolon insertion and
  675. other complicated tasks that occur during lexical analysis.
  676. Specification files are used to build portions of the lexical
  677. analyzer, making it easy to modify.  The three kinds of changes
  678. that are needed most often are the addition of new keywords,
  679. reserved words, and operators.
  680.  
  681.    The identity translator accepts any identifier as a keyword,
  682. leaving its resolution to subsequent processing by the Icon
  683. translator. Nothing need be done to add a new keyword except for
  684. processing it properly in the variant translator.
  685.  
  686.    The specification file tokens.txt contains a list of all
  687. reserved words and operator symbols.  Each symbol has associated
  688. flags that indicate whether it can begin or end an expression.
  689. These flags are used for semicolon insertion.
  690.  
  691.    To add a new reserved word, insert it in proper alphabetical
  692. order in the list of reserved words in tokens.txt and give it a
  693. new token name.  To add a new operator, insert it in the list of
  694. operators in tokens.txt (order there is not important) and give
  695. it a new token name.  The new token names must be added to the
  696. grammar. See Appendix A.
  697.  
  698.    The addition of a new operator also requires modifying the
  699. specification of a finite-state automaton, optab.txt.  Its struc-
  700. ture is straightforward.
  701.  
  702.  
  703. 7.__Modifying_Yacc
  704.  
  705.    Before building a variant translator, it may be necessary to
  706. modify Yacc, since the version of Yacc that normally is distri-
  707. buted with UNIX does not provide enough space to process Icon's
  708. grammar.  To build a version of Yacc with more space, edit the
  709. Yacc source file dextern and change the definition of MEMSIZE in
  710. the HUGE section to
  711.  
  712.         #define MEMSIZE 22000
  713.  
  714. and use
  715.  
  716.         #define HUGE
  717.  
  718. in files. Then rebuild Yacc.
  719.  
  720.  
  721.  
  722.  
  723.  
  724.                              - 10 -
  725.  
  726.  
  727.  
  728.  
  729.  
  730.  
  731.  
  732.  
  733. 8.__Building_a_Variant_Translator
  734.  
  735.    The steps for setting up the directory structure for a variant
  736. translator are:
  737.  
  738.      +  create a directory for the translator
  739.  
  740.      +  make that directory the current directory
  741.  
  742.      +  execute the shell script icon_vt supplied with Version 8
  743.         of Icon
  744.  
  745. For example, if the variant translator is to be in the directory
  746. xtran and Icon is installed in /usr/icon/v8, the following com-
  747. mands will build the variant translator:
  748.  
  749.         mkdir xtran
  750.         cd xtran
  751.         /usr/icon/v8/icon_vt
  752.  
  753.  
  754.    The shell script icon_vt creates a number of files in the new
  755. directory and in two sub-directories: itran and h.  The files
  756. that comprise a variant translator are listed in Appendix C.
  757. Unless changes to the lexical analyzer are needed, at most three
  758. files need to be modified to produce a new translator:
  759.  
  760.         variant.defsvariant macro definitions (initially empty)
  761.         variant.c   parser functions (initially empty)
  762.         itran/icon_g.cYacc grammar for Icon
  763.  
  764. A non-empty variant.c usually requires #include files to provide
  765. needed declarations and definitions. See the example that fol-
  766. lows.
  767.  
  768.    The translator make file, itran/Makefile, is listed in Appen-
  769. dix D.  The make file in the main translator directory just
  770. insures that the program define has be compiled and then does a
  771. make in the itran directory.  Performing a make in the itran
  772. directory first combines variant.defs with the standard macro
  773. definitions (in ident.defs) and processes them to produce the
  774. definition file, itran/gdefs.h. The C preprocessor is then used
  775. to expand the macros in itran/icon_g.c using these definitions
  776. and the result, after some ``house keeping'', is put in
  777. itran/expanded.g. Next, Yacc uses the grammar in itran/expanded.g
  778. to build a new parser, parse.c.  There are over 200 shift/reduce
  779. conflicts in the identity translator.  All of these conflicts are
  780. resolved properly.  More conflicts should be expected if addi-
  781. tions are made to the grammar.  Reduce/reduce conflicts usually
  782. indicate errors in the grammar.  Finally, all the components of
  783. the system are compiled, including variant.c, and linked to pro-
  784. duce vitran, the variant translator.
  785.  
  786.    Most of the errors that may occur in building a variant
  787.  
  788.  
  789.  
  790.                              - 11 -
  791.  
  792.  
  793.  
  794.  
  795.  
  796.  
  797.  
  798.  
  799. translator are obvious and easily fixed. Erroneous changes to the
  800. grammar, however, may be harder to detect and fix. Error messages
  801. from Yacc or from compiling itran/parse.c refer to line numbers
  802. in itran/expanded.g. These errors must be related back to
  803. variant.defs or itran/icon_g.c by inspection of itran/expanded.g.
  804.  
  805.  
  806. 9.__Using_a_Variant_Translator
  807.  
  808.    The translator, vitran, takes an input file on the command
  809. line and translates it.  The specification - in place of an input
  810. file indicates standard input.  The output of vitran is written
  811. to standard output.  For example,
  812.  
  813.         vitran pre.icn >post.icn
  814.  
  815. translates the file pre.icn and produces the output in post.icn.
  816. The suffix .icn on the argument to vitran is optional; the exam-
  817. ple above can be written as:
  818.  
  819.         vitran pre >post.icn
  820.  
  821. Assuming the variant translator produces Icon source language,
  822. post.icn can be translated into object code by
  823.  
  824.         icont post.icn
  825.  
  826. where icont is the standard Icon command processor.
  827.  
  828.    Variant translators accept the same options for translation
  829. that the standard Icon translator does.  For example, the option
  830. -s causes the translator to work silently.  See the manual page
  831. for icont for details [10].
  832.  
  833.  
  834. 10.__An_Example
  835.  
  836.    As an example of the construction of a variant translator,
  837. consider the problem of monitoring string concatenation in Icon
  838. programs, writing out the size of each string constructed by con-
  839. catenation. One way to do this, of course, is to modify Icon
  840. itself, adding the necessary monitoring code to the C function
  841. that performs concatenation.  An alternative approach, which does
  842. not require changes to Icon itself, is to produce a variant
  843. translator that translates concatenation operations into calls of
  844. an Icon procedure, but leaves everything else unchanged:
  845.  
  846.         expr1 || expr2 -> Cat(expr1,expr2)
  847.  
  848. The procedure Cat() might have the form:
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855.  
  856.                              - 12 -
  857.  
  858.  
  859.  
  860.  
  861.  
  862.  
  863.  
  864.  
  865.         procedure Cat(s1,s2)
  866.            write(&errout,"concatenation: ",*s1 + *s2," characters")
  867.            return s1 || s2
  868.         end
  869.  
  870. Such a procedure could be added to a preprocessed program (Cat()
  871. is not preprocessed itself) in order to produce the desired
  872. information when the program is run.
  873.  
  874.    A single definition in variant.defs suffices:
  875.  
  876.         ||(x,y,z)  "Cat("   x        ","      z        ")"
  877.  
  878. Note, however, that Icon also has an augmented assignment opera-
  879. tor for string concatenation:
  880.  
  881.         expr1 ||:= expr2
  882.  
  883. This operation can be handled by the definition
  884.  
  885.         ||:=(x,y,z)         x        " := Cat("        x       ","z")"
  886.  
  887. Observe that this definition is not precisely faithful to the
  888. semantics of Icon, since it causes expr1 to be evaluated twice,
  889. while expr1 is evaluated only once in the true augmented assign-
  890. ment operation. This problem cannot be avoided here, since all
  891. arguments are passed by value in Icon, but in practice, this
  892. discrepancy is unlikely to cause problems.
  893.  
  894.    In the application of such a monitoring facility, it may be
  895. useful to have a provision whereby concatenation can be performed
  896. without being monitored. This can be accomplished by adding an
  897. alternative operator symbol for concatenation, such as
  898.  
  899.         expr1 ~ expr2 -> expr1 || expr2
  900.  
  901. Adding a new operator to the syntax of Icon requires modifying
  902. the grammar in itran/icon_g.c. Since this alternative concatena-
  903. tion operator should have the same precedence and associativity
  904. as the regular concatenation operator, it can be added to the
  905. definition of expr5 (see Appendix A):
  906.  
  907.         expr5      : expr6 ;
  908.                    | expr5 CONCAT expr6 {Bcat($1,$2,$3);} ;
  909.                    | expr5 TILDE expr6 {Bacat($1,$2,$3);} ;
  910.                    | expr5 LCONCAT expr6 {Blcat($1,$2,$3);} ;
  911.  
  912. where TILDE is the token name for ~ . Then the definition of
  913. Bacat() can be added to variant.defs:
  914.  
  915.         Bacat(x,y,z)        x        " || "   z
  916.  
  917. Such changes to icon_g.c usually increase the number of
  918. shift/reduce conflicts encountered by Yacc.
  919.  
  920.  
  921.  
  922.                              - 13 -
  923.  
  924.  
  925.  
  926.  
  927.  
  928.  
  929.  
  930.  
  931.    One difficulty with monitoring concatenation as described
  932. above is that the procedure Cat() must be added to the translated
  933. program.  This can be accomplished automatically by arranging to
  934. have the code for Cat() written out when the variant translator
  935. encounters the main procedure.  This is a case where a parser
  936. function, as mentioned in Section 5, is more appropriate than a
  937. macro definition.
  938.  
  939.    The first step is to change the specifications.  The defini-
  940. tion for the macro, Proc1, that produces procedure declarations
  941. is replaced by a call to a parser function. The changes to
  942. variant.defs are:
  943.  
  944.         %{
  945.         nodeptr proc();
  946.         %}
  947.         Proc1(u,v,w,x,y,z)  proc(u,w,x,y)
  948.  
  949. The C declaration for proc() is included in the file expanded.g
  950. and subsequently incorporated by Yacc into parse.c where the call
  951. to proc() is compiled. Note that proc() returns a nodeptr.
  952.  
  953.    The C function is placed in variant.c. It might have the form
  954.  
  955.         #include "h/config.h"
  956.         #include "itran/tree.h"
  957.         #include "itran/trans.h"
  958.         #include "itran/tproto.h"
  959.  
  960.  
  961.         nodeptr item(), cat(), q();
  962.  
  963.  
  964.         nodeptr proc(u,w,x,y)
  965.         nodeptr u, w, x, y;
  966.            {
  967.            static char *catproc = "procedure Cat(s1,s2)\n\
  968.         write(&errout,\"concatenation:  \",*s1 + *s2,\" characters\")\n\
  969.         return s1 || s2\n\
  970.         end\n";
  971.  
  972.  
  973.            if (strcmp(Str0(item(u,2)),"main") == 0)
  974.               return cat(7,q(catproc),u,q(";\n"),w,x,y,q("end\n"));
  975.            else
  976.               return cat(6,u,q(";\n"),w,x,y,q("end\n"));
  977.            }
  978.  
  979. Thus, when the main procedure is encountered, the text for Cat()
  980. is written out before the text for the main procedure, but all
  981. other procedures are written out as they would be in the absence
  982. of this function.
  983.  
  984.    One disadvantage of this way of providing the text for Cat()
  985.  
  986.  
  987.  
  988.                              - 14 -
  989.  
  990.  
  991.  
  992.  
  993.  
  994.  
  995.  
  996.  
  997. is that the literal string is long, complicated, and difficult to
  998. change. In addition, it is necessary to rebuild the variant
  999. translator in order to change Cat(). Since monitoring of this
  1000. kind is likely to suggest changes to the format or nature of the
  1001. data being written, it is useful to be able to change Cat() more
  1002. easily. One solution to this problem is to produce a link
  1003. declaration for the file containing the translated procedure
  1004. rather than the text of the procedure. With this change, the
  1005. parser function might have the form
  1006.  
  1007.         nodeptr proc(u,w,x,y)
  1008.         nodeptr u, w, x, y;
  1009.            {
  1010.  
  1011.  
  1012.            if (strcmp(Str0(item(u,2)),"main") == 0)
  1013.               return cat(7,q("link cat\n\n"),u,q(";\n"),w,x,y,q("end\n"));
  1014.            else
  1015.               return cat(6,u,q(";\n"),w,x,y,q("end\n"));
  1016.            }
  1017.  
  1018.  
  1019.    The monitoring facility described above produces information
  1020. about all string concatenation operations, but it is not possible
  1021. to distinguish among them. It might be more useful to know the
  1022. amount of concatenation performed by each concatenation opera-
  1023. tion. This can be done if the location of the operator in the
  1024. source program can be identified.  As mentioned in Section 5,
  1025. tree nodes contain line and column information provided by the
  1026. lexical analyzer.  Thus, the translation for the concatenation
  1027. operations could provide this addition information as extra argu-
  1028. ments to Cat(), which then could print out the locations along
  1029. with information about the amount of concatenation.
  1030.  
  1031.         procedure Cat(s1,s2,i,j)
  1032.            write(&errout,"concatenation: ",*s1 + *s2," characters at [",i,",",j,"]")
  1033.            return s1 || s2
  1034.         end
  1035.  
  1036. The specifications for the translation of the concatenation
  1037. operations might be changed to
  1038.  
  1039.         %{
  1040.         nodeptr proc(), Locargs();
  1041.         %}
  1042.         Proc1(u,v,w,x,y,z)  proc(u,w,x,y)
  1043.         ||(x,y,z)  "Cat("   x        ","      z        Locargs(y)")"
  1044.         ||:=(x,y,z)         x        " := Cat("        x       ","zLocargs(y)")"
  1045.         Bacat(x,y,z)        x        " || "   z
  1046.  
  1047. where Locargs is a parser function that produces a string con-
  1048. sisting of the line and column numbers between commas. This func-
  1049. tion might have the form
  1050.  
  1051.  
  1052.  
  1053.  
  1054.                              - 15 -
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.  
  1061.  
  1062.  
  1063.         nodeptr Locargs(x)
  1064.         nodeptr x;
  1065.         {
  1066.              sprintf(strfree,",%d,%d",Col(x),Line(x));
  1067.              return q(putident(strlen(strfree)+1));
  1068.         }
  1069.  
  1070. The C function sprintf() is used to do the formatting, placing
  1071. the resulting string in the translator's allocation region as
  1072. mentioned in Section 5. The string is installed by putident();
  1073. the additional character allows for the fact that such strings
  1074. are stored as Icon strings, not C strings, and the null character
  1075. terminating the C string must be included [11].
  1076.  
  1077.  
  1078. 11.__Conclusions
  1079.  
  1080.    The system described here for producing variant translators
  1081. for Icon has been used successfully to provide support for a
  1082. number of language variants and tools. These include a list scan-
  1083. ning facility [12], a animated display of pattern matching [13],
  1084. An experimental language for manipulating sequences [14,15], a
  1085. SNOBOL4-like language with a syntax similar to Icon [4], an Icon
  1086. program formatter, a tool for monitoring expression evaluation
  1087. events, and a number of simpler tools.
  1088.  
  1089.    The value of being able to construct a variant translator
  1090. quickly and easily is best illustrated by the tool for monitoring
  1091. expression evaluation events. This translator copies input to
  1092. output, inserting calls on procedures that tally expression
  1093. activations, the production of results, and expression resump-
  1094. tions. A similar system was built for Version 2 of Icon [16] and
  1095. was used to analyze the performance and behavior of generators.
  1096. In that case, the code generator and run-time system were modi-
  1097. fied extensively. This involved weeks of tedious and difficult
  1098. work that required expert knowledge of the internal structure of
  1099. the Version 2 system. The variant translator for Version 8 was
  1100. written in a few hours, and required only a knowledge of the for-
  1101. mat of variant macro specifications and the Icon source language
  1102. itself.  The monitoring of expression evaluation events in Ver-
  1103. sion 8 probably would not have been undertaken if it had been
  1104. necessary to modify the code generator and the run-time system.
  1105.  
  1106.    The usefulness of the system described here depends heavily on
  1107. its support software. The ability to specify macro definitions in
  1108. a simple format, and particularly to be able to provide a single
  1109. specification for the translation for all operators in a class,
  1110. makes it easy to write many variant translators that otherwise
  1111. would be impractically tedious.
  1112.  
  1113.    Although the system described in this report is specifically
  1114. tailored to Icon, the techniques have much broader applicability.
  1115. The automatic generation of such systems from grammatical specif-
  1116. ications is an interesting project.
  1117.  
  1118.  
  1119.  
  1120.                              - 16 -
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.  
  1127.  
  1128.  
  1129. Acknowledgements
  1130.  
  1131.    Tim Budd's Cg preprocessor was the inspiration for the Icon
  1132. variant translator system described here. Bill Mitchell assisted
  1133. in adapting the standard Icon translator to its use here. Tim
  1134. Budd, Dave Hanson, Bill Mitchell, Janalee O'Bagy, and Steve
  1135. Wampler made a number of helpful suggestions on the variant
  1136. translator system and the presentation of the material in this
  1137. report.  Y-H Cheng provided several corrections to earlier ver-
  1138. sions of this report.
  1139.  
  1140. References
  1141.  
  1142.  
  1143. 1.   B. W. Kernighan, ``Ratfor - A Preprocessor for a Rational
  1144.      Fortran'', Software-Practice & Experience 5(1975), 395-406.
  1145.  
  1146. 2.   T. A. Budd, ``An Implementation of Generators in C'', J.
  1147.      Computer Lang. 7(1982), 69-87.
  1148.  
  1149. 3.   R. E. Griswold and M. T. Griswold, The Icon Programming
  1150.      Language, Prentice-Hall, Inc., Englewood Cliffs, NJ, 1983.
  1151.  
  1152. 4.   R. E. Griswold, Rebus - A SNOBOL4/Icon Hybrid, The Univ. of
  1153.      Arizona Tech. Rep. 84-9, 1984.
  1154.  
  1155. 5.   J. L. Steffen, ``Ctrace - A Portable Debugger for C
  1156.      Programs'', UNICOM Conference Proceedings, Jan. 1983, 187-
  1157.      191.  San Diego, California.
  1158.  
  1159. 6.   S. C. Kendall, ``Bcc: Runtime Checking for C Programs'',
  1160.      USENIX Software Tools Summer 1983 Toronto Conference
  1161.      Proceedings, 1983, 5-16.
  1162.  
  1163. 7.   M. E. Lesk and E. Schmidt, Lex - A Lexical Analyzer
  1164.      Generator, Bell Laboratories, Murray Hill, New Jersey, 1979.
  1165.  
  1166. 8.   S. C. Johnson, Yacc: Yet Another Compiler-Compiler, Bell
  1167.      Laboratories, Murray Hill, New Jersey, 1978.
  1168.  
  1169. 9.   R. E. Griswold, Version 8 of Icon, The Univ. of Arizona
  1170.      Tech. Rep. 90-1, 1990.
  1171.  
  1172. 10.  R. E. Griswold, ICONT(1), manual page for UNIX Programmer's
  1173.      Manual, The Univ. of Arizona Icon Project Document IPD109,
  1174.      1990.
  1175.  
  1176. 11.  R. E. Griswold and M. T. Griswold, The Implementation of the
  1177.      Icon Programming Language, Princeton University Press, 1986.
  1178.  
  1179. 12.  A. J. Anderson and R. E. Griswold, Unifying List and String
  1180.      Processing in Icon, The Univ. of Arizona Tech. Rep. 83-4,
  1181.      1983.
  1182.  
  1183.  
  1184.  
  1185.  
  1186.                              - 17 -
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.  
  1193.  
  1194.  
  1195. 13.  K. Walker and R. E. Griswold, A Pattern-Matching Laboratory;
  1196.      Part I - An Animated Display of String Pattern Matching, The
  1197.      Univ. of Arizona Tech. Rep. 86-1, 1986.
  1198.  
  1199. 14.  R. E. Griswold and J. O'Bagy, Seque: A Language for
  1200.      Programming with Streams, The Univ. of Arizona Tech. Rep.
  1201.      85-2, 1985.
  1202.  
  1203. 15.  R. E. Griswold and J. O'Bagy, Reference Manual for the Seque
  1204.      Programming Language, The Univ. of Arizona Tech. Rep. 85-4,
  1205.      1985.
  1206.  
  1207. 16.  C. A. Coutant, R. E. Griswold and D. R. Hanson, ``Measuring
  1208.      the Performance and Behavior of Icon Programs'', IEEE Trans.
  1209.      on Software Eng. SE-9, 1 (Jan. 1983), 93-103.
  1210.  
  1211.  
  1212.  
  1213.  
  1214.  
  1215.  
  1216.  
  1217.  
  1218.  
  1219.  
  1220.  
  1221.  
  1222.  
  1223.  
  1224.  
  1225.  
  1226.  
  1227.  
  1228.  
  1229.  
  1230.  
  1231.  
  1232.  
  1233.  
  1234.  
  1235.  
  1236.  
  1237.  
  1238.  
  1239.  
  1240.  
  1241.  
  1242.  
  1243.  
  1244.  
  1245.  
  1246.  
  1247.  
  1248.  
  1249.  
  1250.  
  1251.  
  1252.                              - 18 -
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.  
  1259.  
  1260.  
  1261.                     Appendix A - The Icon Grammar
  1262.  
  1263.  
  1264.  
  1265. /*
  1266.  * icong.c -- grammar for Icon Version 8.0.
  1267.  *
  1268.  * NOTE: Any modifications of this grammar should be
  1269.  * propagated to any affected macro in gdefs.h.
  1270.  */
  1271. #include "../h/define.h"
  1272.  
  1273.  
  1274. /* primitive tokens */
  1275.  
  1276.  
  1277. %token  CSETLIT
  1278.         EOFX
  1279.         IDENT
  1280.         INTLIT
  1281.         REALLIT
  1282.         STRINGLIT
  1283.  
  1284.  
  1285. /* reserved words */
  1286.  
  1287.  
  1288.  
  1289.  
  1290.  
  1291.  
  1292.  
  1293.  
  1294.  
  1295.  
  1296.  
  1297.  
  1298.  
  1299.  
  1300.  
  1301.  
  1302.  
  1303.  
  1304.  
  1305.  
  1306.  
  1307.  
  1308.  
  1309.  
  1310.  
  1311.  
  1312.  
  1313.  
  1314.  
  1315.  
  1316.  
  1317.  
  1318.                              - 19 -
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.  
  1325.  
  1326.  
  1327. %token  BREAK           /* break */
  1328.         BY              /* by */
  1329.         CASE            /* case */
  1330.         CREATE          /* create */
  1331.         DEFAULT         /* default */
  1332.         DO              /* do */
  1333.         ELSE            /* else */
  1334.         END             /* end */
  1335.         EVERY           /* every */
  1336.         FAIL            /* fail */
  1337.         GLOBAL          /* global */
  1338.         IF              /* if */
  1339.         INITIAL         /* initial */
  1340.         LINK            /* link */
  1341.         LOCAL           /* link */
  1342.         NEXT            /* next */
  1343.         NOT             /* not */
  1344.         OF              /* of */
  1345.         PROCEDURE       /* procedure */
  1346.         RECORD          /* record */
  1347.         REPEAT          /* repeat */
  1348.         RETURN          /* return */
  1349.         STATIC          /* static */
  1350.         SUSPEND         /* suspend */
  1351.         THEN            /* then */
  1352.         TO              /* to */
  1353.         UNTIL           /* until */
  1354.         WHILE           /* while */
  1355.  
  1356.  
  1357.  
  1358.  
  1359.  
  1360.  
  1361.  
  1362.  
  1363.  
  1364.  
  1365.  
  1366.  
  1367.  
  1368.  
  1369.  
  1370.  
  1371.  
  1372.  
  1373.  
  1374.  
  1375.  
  1376.  
  1377.  
  1378.  
  1379.  
  1380.  
  1381.  
  1382.  
  1383.  
  1384.                              - 20 -
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.  
  1391.  
  1392.  
  1393. /* operators */
  1394. %token  ASSIGN          /* := */
  1395.         AT              /* @ */
  1396.         AUGACT          /* @:= */
  1397.         AUGAND          /* &:= */
  1398.         AUGEQ           /* =:= */
  1399.         AUGEQV          /* ===:= */
  1400.         AUGGE           /* >=:= */
  1401.         AUGGT           /* >:= */
  1402.         AUGLE           /* <=:= */
  1403.         AUGLT           /* <:= */
  1404.         AUGNE           /* ~=:= */
  1405.         AUGNEQV         /* ~===:= */
  1406.         AUGSEQ          /* ==:= */
  1407.         AUGSGE          /* >>=:= */
  1408.         AUGSGT          /* >>:= */
  1409.         AUGSLE          /* <<=:= */
  1410.         AUGSLT          /* <<:= */
  1411.         AUGSNE          /* ~==:= */
  1412.         BACKSLASH       /* \ */
  1413.         BANG            /* ! */
  1414.         BAR             /* | */
  1415.         CARET           /* $ */
  1416.         CARETASGN       /* $:= */
  1417.         COLON           /* : */
  1418.         COMMA           /* , */
  1419.         CONCAT          /* || */
  1420.         CONCATASGN      /* ||:= */
  1421.         CONJUNC         /* & */
  1422.         DIFF            /* -- */
  1423.         DIFFASGN                /* --:= */
  1424.         DOT             /* . */
  1425.         EQUIV           /* === */
  1426.         INTER           /* ** */
  1427.         INTERASGN       /* **:= */
  1428.         LBRACE          /* { */
  1429.         LBRACK          /*  */
  1430.         LCONCAT         /* ||| */
  1431.         LCONCATASGN     /* |||:= */
  1432.         LEXEQ           /* == */
  1433.         LEXGE           /* >>= */
  1434.         LEXGT           /* >> */
  1435.         LEXLE           /* <<= */
  1436.         LEXLT           /* << */
  1437.         LEXNE           /* ~== */
  1438.         LPAREN          /* ( */
  1439.         MCOLON          /* -: */
  1440.         MINUS           /* - */
  1441.         MINUSASGN       /* -:= */
  1442.         MOD             /* % */
  1443.         MODASGN         /* %:= */
  1444.         NOTEQUIV                /* ~=== */
  1445.         NUMEQ           /* = */
  1446.         NUMGE           /* >= */
  1447.  
  1448.  
  1449.  
  1450.                              - 21 -
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456.  
  1457.  
  1458.  
  1459.         NUMGT           /* > */
  1460.         NUMLE           /* <= */
  1461.         NUMLT           /* < */
  1462.         NUMNE           /* ~= */
  1463.         PCOLON          /* +: */
  1464.         PLUS            /* + */
  1465.         PLUSASGN                /* +:= */
  1466.         QMARK           /* ? */
  1467.         RBRACE          /* } */
  1468.         RBRACK          /* ] */
  1469.         REVASSIGN       /* <- */
  1470.         REVSWAP         /* <-> */
  1471.         RPAREN          /* ) */
  1472.         SCANASGN                /* ?:= */
  1473.         SEMICOL         /* ; */
  1474.         SLASH           /* / */
  1475.         SLASHASGN       /* /:= */
  1476.         STAR            /* * */
  1477.         STARASGN                /* *:= */
  1478.         SWAP            /* :=: */
  1479.         TILDE           /* ~ */
  1480.         UNION           /* ++ */
  1481.         UNIONASGN       /* ++:= */
  1482. %{
  1483. /*#include "../h/config.h"*/
  1484. /*#include "tproto.h"*/
  1485. /*#include "trans.h"*/
  1486. /*#include "tsym.h"*/
  1487. /*#include "tree.h"*/
  1488. /*#include "../h/keyword.h"*/
  1489. /*#define YYSTYPE nodeptr*/
  1490. /*#define YYMAXDEPTH 500*/
  1491. #include "gdefs.h"
  1492. %}
  1493.  
  1494.  
  1495. %%
  1496.  
  1497.  
  1498. program : decls EOFX {Progend($1,$2);} ;
  1499.  
  1500.  
  1501. decls   : ;
  1502.         | decls decl ;
  1503.  
  1504.  
  1505. decl    : record {Recdcl($1);} ;
  1506.         | proc {Procdcl($1);} ;
  1507.         | global {Globdcl($1);} ;
  1508.         | link {Linkdcl($1);} ;
  1509.  
  1510.  
  1511. link    : LINK lnklist {Link($1, $2);} ;
  1512.  
  1513.  
  1514.  
  1515.  
  1516.                              - 22 -
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522.  
  1523.  
  1524.  
  1525. lnklist : lnkfile       ;
  1526.         | lnklist COMMA lnkfile {Lnklist($1,$2,$3);} ;
  1527.  
  1528.  
  1529. lnkfile : IDENT {Lnkfile1($1);} ;
  1530.         | STRINGLIT {Lnkfile2($1);} ;
  1531.  
  1532.  
  1533. global  : GLOBAL {Global0($1);} idlist  {Global1($1, $2, $3);} ;
  1534.  
  1535.  
  1536. record  : RECORD {Record1($1);} IDENT LPAREN fldlist RPAREN {
  1537.                 Record2($1,$2,$3,$4,$5,$6);
  1538.                 } ;
  1539.  
  1540.  
  1541. fldlist : {Arglist1();} ;
  1542.         | idlist {Arglist2($1);} ;
  1543.  
  1544.  
  1545. proc    : prochead SEMICOL locals initial procbody END {
  1546.                 Proc1($1,$2,$3,$4,$5,$6);
  1547.                 } ;
  1548.  
  1549.  
  1550. prochead        : PROCEDURE {Prochead1($1);} IDENT LPAREN arglist RPAREN {
  1551.                 Prochead2($1,$2,$3,$4,$5,$6);
  1552.                 } ;
  1553.  
  1554.  
  1555. arglist : {Arglist1();} ;
  1556.         | idlist {Arglist2($1);} ;
  1557.         | idlist LBRACK RBRACK {Arglist3($1);} ;
  1558.  
  1559.  
  1560.  
  1561.  
  1562. idlist  : IDENT {
  1563.                 Ident($1);
  1564.                 } ;
  1565.         | idlist COMMA IDENT {
  1566.                 Idlist($1,$2,$3);
  1567.                 } ;
  1568.  
  1569.  
  1570. locals  : {Locals1();} ;
  1571.         | locals retention idlist SEMICOL {Locals2($1,$2,$3,$4);} ;
  1572.  
  1573.  
  1574. retention       : LOCAL {Local($1);} ;
  1575.         | STATIC {Static($1);} ;
  1576.  
  1577.  
  1578.  
  1579.  
  1580.  
  1581.  
  1582.                              - 23 -
  1583.  
  1584.  
  1585.  
  1586.  
  1587.  
  1588.  
  1589.  
  1590.  
  1591. initial : {Initial1();} ;
  1592.         | INITIAL expr SEMICOL {Initial2($1,$2,$3);} ;
  1593.  
  1594.  
  1595. procbody        : {Procbody1();} ;
  1596.         | nexpr SEMICOL procbody {Procbody2($1,$2,$3);} ;
  1597.  
  1598.  
  1599. nexpr   : {Nexpr();} ;
  1600.         | expr ;
  1601.  
  1602.  
  1603. expr    : expr1a        ;
  1604.         | expr CONJUNC expr1a   {Bamper($1,$2,$3);} ;
  1605.  
  1606.  
  1607. expr1a  : expr1 ;
  1608.         | expr1a QMARK expr1    {Bques($1,$2,$3);} ;
  1609.  
  1610.  
  1611. expr1   : expr2 ;
  1612.         | expr2 SWAP expr1 {Bswap($1,$2,$3);} ;
  1613.         | expr2 ASSIGN expr1 {Bassgn($1,$2,$3);} ;
  1614.         | expr2 REVSWAP expr1 {Brswap($1,$2,$3);} ;
  1615.         | expr2 REVASSIGN expr1 {Brassgn($1,$2,$3);} ;
  1616.         | expr2 CONCATASGN expr1 {Baugcat($1,$2,$3);} ;
  1617.         | expr2 LCONCATASGN expr1 {Bauglcat($1,$2,$3);} ;
  1618.         | expr2 DIFFASGN expr1 {Bdiffa($1,$2,$3);} ;
  1619.         | expr2 UNIONASGN expr1 {Buniona($1,$2,$3);} ;
  1620.         | expr2 PLUSASGN expr1 {Bplusa($1,$2,$3);} ;
  1621.         | expr2 MINUSASGN expr1 {Bminusa($1,$2,$3);} ;
  1622.         | expr2 STARASGN expr1 {Bstara($1,$2,$3);} ;
  1623.         | expr2 INTERASGN expr1 {Bintera($1,$2,$3);} ;
  1624.         | expr2 SLASHASGN expr1 {Bslasha($1,$2,$3);} ;
  1625.         | expr2 MODASGN expr1 {Bmoda($1,$2,$3);} ;
  1626.         | expr2 CARETASGN expr1 {Bcareta($1,$2,$3);} ;
  1627.         | expr2 AUGEQ expr1 {Baugeq($1,$2,$3);} ;
  1628.         | expr2 AUGEQV expr1 {Baugeqv($1,$2,$3);} ;
  1629.         | expr2 AUGGE expr1 {Baugge($1,$2,$3);} ;
  1630.         | expr2 AUGGT expr1 {Bauggt($1,$2,$3);} ;
  1631.         | expr2 AUGLE expr1 {Baugle($1,$2,$3);} ;
  1632.         | expr2 AUGLT expr1 {Bauglt($1,$2,$3);} ;
  1633.         | expr2 AUGNE expr1 {Baugne($1,$2,$3);} ;
  1634.         | expr2 AUGNEQV expr1 {Baugneqv($1,$2,$3);} ;
  1635.         | expr2 AUGSEQ expr1 {Baugseq($1,$2,$3);} ;
  1636.         | expr2 AUGSGE expr1 {Baugsge($1,$2,$3);} ;
  1637.         | expr2 AUGSGT expr1 {Baugsgt($1,$2,$3);} ;
  1638.         | expr2 AUGSLE expr1 {Baugsle($1,$2,$3);} ;
  1639.         | expr2 AUGSLT expr1 {Baugslt($1,$2,$3);} ;
  1640.         | expr2 AUGSNE expr1 {Baugsne($1,$2,$3);} ;
  1641.         | expr2 SCANASGN expr1 {Baugques($1,$2,$3);} ;
  1642.         | expr2 AUGAND expr1 {Baugamper($1,$2,$3);} ;
  1643.         | expr2 AUGACT expr1 {Baugact($1,$2,$3);} ;
  1644.  
  1645.  
  1646.  
  1647.  
  1648.                              - 24 -
  1649.  
  1650.  
  1651.  
  1652.  
  1653.  
  1654.  
  1655.  
  1656.  
  1657. expr2   : expr3 ;
  1658.         | expr2 TO expr3 {To0($1,$2,$3);} ;
  1659.         | expr2 TO expr3 BY expr3 {To1($1,$2,$3,$4,$5);} ;
  1660.  
  1661.  
  1662. expr3   : expr4 ;
  1663.         | expr4 BAR expr3 {Alt($1,$2,$3);} ;
  1664.  
  1665.  
  1666. expr4   : expr5 ;
  1667.         | expr4 LEXEQ expr5 {Bseq($1,$2,$3);} ;
  1668.         | expr4 LEXGE expr5 {Bsge($1,$2,$3);} ;
  1669.         | expr4 LEXGT expr5 {Bsgt($1,$2,$3);} ;
  1670.         | expr4 LEXLE expr5 {Bsle($1,$2,$3);} ;
  1671.         | expr4 LEXLT expr5 {Bslt($1,$2,$3);} ;
  1672.         | expr4 LEXNE expr5 {Bsne($1,$2,$3);} ;
  1673.         | expr4 NUMEQ expr5 {Beq($1,$2,$3);} ;
  1674.         | expr4 NUMGE expr5 {Bge($1,$2,$3);} ;
  1675.         | expr4 NUMGT expr5 {Bgt($1,$2,$3);} ;
  1676.         | expr4 NUMLE expr5 {Ble($1,$2,$3);} ;
  1677.         | expr4 NUMLT expr5 {Blt($1,$2,$3);} ;
  1678.         | expr4 NUMNE expr5 {Bne($1,$2,$3);} ;
  1679.         | expr4 EQUIV expr5 {Beqv($1,$2,$3);} ;
  1680.         | expr4 NOTEQUIV expr5 {Bneqv($1,$2,$3);} ;
  1681.  
  1682.  
  1683. expr5   : expr6 ;
  1684.         | expr5 CONCAT expr6 {Bcat($1,$2,$3);} ;
  1685.         | expr5 LCONCAT expr6 {Blcat($1,$2,$3);} ;
  1686.  
  1687.  
  1688. expr6   : expr7 ;
  1689.         | expr6 PLUS expr7 {Bplus($1,$2,$3);} ;
  1690.         | expr6 DIFF expr7 {Bdiff($1,$2,$3);} ;
  1691.         | expr6 UNION expr7 {Bunion($1,$2,$3);} ;
  1692.         | expr6 MINUS expr7 {Bminus($1,$2,$3);} ;
  1693.  
  1694.  
  1695. expr7   : expr8 ;
  1696.         | expr7 STAR expr8 {Bstar($1,$2,$3);} ;
  1697.         | expr7 INTER expr8 {Binter($1,$2,$3);} ;
  1698.         | expr7 SLASH expr8 {Bslash($1,$2,$3);} ;
  1699.         | expr7 MOD expr8 {Bmod($1,$2,$3);} ;
  1700.  
  1701.  
  1702. expr8   : expr9 ;
  1703.         | expr9 CARET expr8 {Bcaret($1,$2,$3);} ;
  1704.  
  1705.  
  1706. expr9   : expr10 ;
  1707.         | expr9 BACKSLASH expr10 {Blim($1,$2,$3);} ;
  1708.         | expr9 AT expr10 {Bact($1,$2,$3);};
  1709.         | expr9 BANG expr10 {Apply($1,$2,$3);};
  1710.  
  1711.  
  1712.  
  1713.  
  1714.                              - 25 -
  1715.  
  1716.  
  1717.  
  1718.  
  1719.  
  1720.  
  1721.  
  1722.  
  1723. expr10  : expr11 ;
  1724.         | AT expr10 {Uat($1,$2);} ;
  1725.         | NOT expr10 {Unot($1,$2);} ;
  1726.         | BAR expr10 {Ubar($1,$2);} ;
  1727.         | CONCAT expr10 {Uconcat($1,$2);} ;
  1728.         | LCONCAT expr10 {Ulconcat($1,$2);} ;
  1729.         | DOT expr10 {Udot($1,$2);} ;
  1730.         | BANG expr10 {Ubang($1,$2);} ;
  1731.         | DIFF expr10 {Udiff($1,$2);} ;
  1732.         | PLUS expr10 {Uplus($1,$2);} ;
  1733.         | STAR expr10 {Ustar($1,$2);} ;
  1734.         | SLASH expr10 {Uslash($1,$2);} ;
  1735.         | CARET expr10 {Ucaret($1,$2);} ;
  1736.         | INTER expr10 {Uinter($1,$2);} ;
  1737.         | TILDE expr10 {Utilde($1,$2);} ;
  1738.         | MINUS expr10 {Uminus($1,$2);} ;
  1739.         | NUMEQ expr10 {Unumeq($1,$2);} ;
  1740.         | NUMNE expr10 {Unumne($1,$2);} ;
  1741.         | LEXEQ expr10 {Ulexeq($1,$2);} ;
  1742.         | LEXNE expr10 {Ulexne($1,$2);} ;
  1743.         | EQUIV expr10 {Uequiv($1,$2);} ;
  1744.         | UNION expr10 {Uunion($1,$2);} ;
  1745.         | QMARK expr10 {Uqmark($1,$2);} ;
  1746.         | NOTEQUIV expr10 {Unotequiv($1,$2);} ;
  1747.         | BACKSLASH expr10 {Ubackslash($1,$2);} ;
  1748. expr11  : literal ;
  1749.         | section ;
  1750.         | return ;
  1751.         | if ;
  1752.         | case ;
  1753.         | while ;
  1754.         | until ;
  1755.         | every ;
  1756.         | repeat ;
  1757.         | CREATE expr {Create($1,$2);} ;
  1758.         | IDENT {Var($1);} ;
  1759.         | NEXT {Next($1);} ;
  1760.         | BREAK nexpr {Break($1,$2);} ;
  1761.         | LPAREN exprlist RPAREN {Paren($1,$2,$3);} ;
  1762.         | LBRACE compound RBRACE {Brace($1,$2,$3);} ;
  1763.         | LBRACK exprlist RBRACK {Brack($1,$2,$3);} ;
  1764.         | expr11 LBRACK nexpr RBRACK {Subscript($1,$2,$3,$4);} ;
  1765.         | expr11 LBRACE RBRACE {Pdco0($1,$2,$3);} ;
  1766.         | expr11 LBRACE pdcolist RBRACE {Pdco1($1,$2,$3,$4);} ;
  1767.         | expr11 LPAREN exprlist RPAREN {Invoke($1,$2,$3,$4);} ;
  1768.         | expr11 DOT IDENT {Field($1,$2,$3);} ;
  1769.         | CONJUNC FAIL {Kfail($1,$2);} ;
  1770.         | CONJUNC IDENT {Keyword($1,$2);} ;
  1771.  
  1772.  
  1773. while   : WHILE expr {While0($1,$2);} ;
  1774.         | WHILE expr DO expr {While1($1,$2,$3,$4);} ;
  1775.  
  1776.  
  1777.  
  1778.  
  1779.  
  1780.                              - 26 -
  1781.  
  1782.  
  1783.  
  1784.  
  1785.  
  1786.  
  1787.  
  1788.  
  1789. until   : UNTIL expr {Until0($1,$2);} ;
  1790.         | UNTIL expr DO expr {Until1($1,$2,$3,$4);} ;
  1791.  
  1792.  
  1793. every   : EVERY expr {Every0($1,$2);} ;
  1794.         | EVERY expr DO expr {Every1($1,$2,$3,$4);} ;
  1795.  
  1796.  
  1797. repeat  : REPEAT expr {Repeat($1,$2);} ;
  1798.  
  1799.  
  1800. return  : FAIL {Fail($1);} ;
  1801.         | RETURN nexpr {Return($1,$2);} ;
  1802.         | SUSPEND nexpr {Suspend0($1,$2);} ;
  1803.         | SUSPEND expr DO expr {Suspend1($1,$2,$3,$4);};
  1804.  
  1805.  
  1806. if      : IF expr THEN expr {If0($1,$2,$3,$4);} ;
  1807.         | IF expr THEN expr ELSE expr {If1($1,$2,$3,$4,$5,$6);} ;
  1808.  
  1809.  
  1810. case    : CASE expr OF LBRACE caselist RBRACE {Case($1,$2,$3,$4,$5,$6);} ;
  1811.  
  1812.  
  1813. caselist        : cclause ;
  1814.         | caselist SEMICOL cclause {Caselist($1,$2,$3);} ;
  1815.  
  1816.  
  1817. cclause : DEFAULT COLON expr {Cclause0($1,$2,$3);} ;
  1818.         | expr COLON expr {Cclause1($1,$2,$3);} ;
  1819.  
  1820.  
  1821. exprlist        : nexpr
  1822.         | exprlist COMMA nexpr {Exprlist($1,$2,$3);} ;
  1823.  
  1824.  
  1825. pdcolist        : nexpr {
  1826.                 Pdcolist0($1);
  1827.                 } ;
  1828.         | pdcolist COMMA nexpr {
  1829.                 Pdcolist1($1,$2,$3);
  1830.                 } ;
  1831.  
  1832.  
  1833. literal : INTLIT {Iliter($1);} ;
  1834.         | REALLIT {Rliter($1);} ;
  1835.         | STRINGLIT {Sliter($1);} ;
  1836.         | CSETLIT {Cliter($1);} ;
  1837.  
  1838.  
  1839. section : expr11 LBRACK expr sectop expr RBRACK {Section($1,$2,$3,$4,$5,$6);} ;
  1840.  
  1841.  
  1842.  
  1843.  
  1844.  
  1845.  
  1846.                              - 27 -
  1847.  
  1848.  
  1849.  
  1850.  
  1851.  
  1852.  
  1853.  
  1854.  
  1855. sectop  : COLON {Colon($1);} ;
  1856.         | PCOLON {Pcolon($1);} ;
  1857.         | MCOLON {Mcolon($1);} ;
  1858.  
  1859.  
  1860. compound        : nexpr ;
  1861.         | nexpr SEMICOL compound {Compound($1,$2,$3);} ;
  1862.  
  1863.  
  1864. program : error decls EOFX ;
  1865. proc    : prochead error procbody END ;
  1866. expr    : error ;
  1867. %%
  1868.  
  1869.  
  1870.  
  1871.  
  1872.  
  1873.  
  1874.  
  1875.  
  1876.  
  1877.  
  1878.  
  1879.  
  1880.  
  1881.  
  1882.  
  1883.  
  1884.  
  1885.  
  1886.  
  1887.  
  1888.  
  1889.  
  1890.  
  1891.  
  1892.  
  1893.  
  1894.  
  1895.  
  1896.  
  1897.  
  1898.  
  1899.  
  1900.  
  1901.  
  1902.  
  1903.  
  1904.  
  1905.  
  1906.  
  1907.  
  1908.  
  1909.  
  1910.  
  1911.  
  1912.                              - 28 -
  1913.  
  1914.  
  1915.  
  1916.  
  1917.  
  1918.  
  1919.  
  1920.  
  1921.        Appendix B - Specifications for the Identity Translator
  1922.  
  1923.  
  1924.  
  1925. %{
  1926. nodeptr q();
  1927. nodeptr cat();
  1928. %}
  1929.  
  1930.  
  1931. #  Declaration Syntax
  1932. #
  1933. #      declarations
  1934. #
  1935. %{
  1936. #define Globdcl(x)  if (!nocode) treeprt(x); treeinit()
  1937. #define Linkdcl(x)  if (!nocode) treeprt(x); treeinit()
  1938. #define Procdcl(x)  if (!nocode) treeprt(x); treeinit()
  1939. #define Recdcl(x)   if (!nocode) treeprt(x); treeinit()
  1940. %}
  1941.  
  1942.  
  1943. #
  1944. #      syntax subsidiary to declarations
  1945. #
  1946. Arglist1()          ""
  1947. Arglist2(x)         x
  1948. Arglist3(x)         x       "[]"
  1949. Global0(x)          ""
  1950. Global1(x,y,z)      "global "       z       "\n"
  1951. Initial1()          ""
  1952. Initial2(x,y,z)     "initial "      y       ";\n"
  1953. Link(x,y)           "link " y       "\n"
  1954. Lnkfile1(x)         x
  1955. Lnkfile2(x)         "\""    x       "\""
  1956. Lnklist(x,y,z)      x       ","     z
  1957. Local(x)            "local "
  1958. Locals1()           ""
  1959. Locals2(w,x,y,z)    w       x       y       ";\n"
  1960. Record1(x)          ""
  1961. Proc1(u,v,w,x,y,z)  u       ";\n"   w       x       y       "end\n"
  1962. Record2(u,v,w,x,y,z)        "record "       w       "("     y")\n"
  1963. Procbody1()         ""
  1964. Procbody2(x,y,z)    x       ";\n"   z
  1965. Prochead1(x)        ""
  1966. Prochead2(u,v,w,x,y,z)      "procedure "    w       "("     y")"
  1967. Static(x)           "static "
  1968.  
  1969.  
  1970.  
  1971.  
  1972.  
  1973.  
  1974.  
  1975.  
  1976.  
  1977.  
  1978.                              - 29 -
  1979.  
  1980.  
  1981.  
  1982.  
  1983.  
  1984.  
  1985.  
  1986.  
  1987. #
  1988. #  Expression Syntax
  1989. #
  1990. #      elements
  1991. #
  1992. Cliter(x)           "'"     x       "'"
  1993. Ident(x)            x
  1994. Idlist(x,y,z)       x       ","     z
  1995. Iliter(x)           x
  1996. Keyword(x,y)        "&"     y
  1997. Kfail(x,y)          "&fail"
  1998. Nexpr()             ""
  1999. Rliter(x)           x
  2000. Sliter(x)           "\""    x       "\""
  2001. Var(x)              x
  2002.  
  2003.  
  2004. #
  2005. #      reserved-word syntax
  2006. #
  2007. Break(x,y)          "break "        y
  2008. Case(u,v,w,x,y,z)   "case " v       " of {\n"       y       "\n}"
  2009. Caselist(x,y,z)     x       ";\n"   z
  2010. Cclause0(x,y,z)     "default:"      z
  2011. Cclause1(x,y,z)     x       ":"     z
  2012. Create(x,y)         "create "       y
  2013. Every0(x,y)         "every "        y
  2014. Every1(w,x,y,z)     "every "        x       " do "  z
  2015. Fail(x)             "fail"
  2016. If0(w,x,y,z)        "if "   x       " then "        z
  2017. If1(u,v,w,x,y,z)    "if "   v       " then "        x       " else "z
  2018. Next(x)             "next "
  2019. Repeat(x,y)         "repeat "       y
  2020. Return(x,y)         "return "       y
  2021. Suspend0(x,y)       "suspend "      y
  2022. Suspend1(w,x,y,z)   "suspend "      x       " do "  z
  2023. To0(x,y,z)          x       " to "  z
  2024. To1(v,w,x,y,z)      v       " to "  x       " by "  z
  2025. Unot(x,y)           "not "  y
  2026. Until0(x,y)         "until "        y
  2027. Until1(w,x,y,z)     "until "        x       " do "  z
  2028. While0(x,y)         "while "        y
  2029. While1(w,x,y,z)     "while "        x       " do "  z
  2030.  
  2031.  
  2032. #
  2033. #      operator syntax
  2034. #
  2035. #      binary operators
  2036. #
  2037. <bop>(x,y,z)        x       " <bop> "       z
  2038. <aop>(x,y,z)        x       " <aop> "       z
  2039. <bcs>(x,y,z)        x       " <bcs> "       z
  2040.  
  2041.  
  2042.  
  2043.  
  2044.                              - 30 -
  2045.  
  2046.  
  2047.  
  2048.  
  2049.  
  2050.  
  2051.  
  2052.  
  2053. #
  2054. #      unary operators
  2055. #
  2056. <uop>(x,y)          "<uop>" y
  2057. <ucs>(x,y)          "<ucs>" y
  2058.  
  2059.  
  2060. #
  2061. #      miscellaneous expressions
  2062. #
  2063. Apply(x,y,z)        x       "!"     z
  2064. Brace(x,y,z)        "{\n"   y       "\n}"
  2065. Brack(x,y,z)        "["     y       "]"
  2066. Colon(x)            ":"
  2067. Compound(x,y,z)     x       ";\n"   z
  2068. Exprlist(x,y,z)     x       ","     z
  2069. Field(x,y,z)        x       "."     z
  2070. Invoke(w,x,y,z)     w       "("     y       ")"
  2071. Mcolon(x)           "-:"
  2072. Paren(x,y,z)        "("     y       ")"
  2073. Pcolon(x)           "+:"
  2074. Pdco0(x,y,z)        x       "{"     "}"
  2075. Pdco1(w,x,y,z)      w       "{"     y       "}"
  2076. Pdcolist0(x)        x
  2077. Pdcolist1(x,y,z)    x       ","     z
  2078. Progend(x,y)        ""
  2079. Section(u,v,w,x,y,z)        u       "["     w       x       y"]"
  2080. Subscript(w,x,y,z)  w       "["     y       "]"
  2081.  
  2082.  
  2083.  
  2084.  
  2085.  
  2086.  
  2087.  
  2088.  
  2089.  
  2090.  
  2091.  
  2092.  
  2093.  
  2094.  
  2095.  
  2096.  
  2097.  
  2098.  
  2099.  
  2100.  
  2101.  
  2102.  
  2103.  
  2104.  
  2105.  
  2106.  
  2107.  
  2108.  
  2109.  
  2110.                              - 31 -
  2111.  
  2112.  
  2113.  
  2114.  
  2115.  
  2116.  
  2117.  
  2118.  
  2119.          Appendix C - Files for Building a Variant Translator
  2120.  
  2121.  
  2122.  
  2123.      Note: Other files are created when a variant translator is
  2124.      constructed.
  2125.  
  2126.  
  2127. Makefile            controlling Makefile
  2128. bsyms               macro names for binary operators
  2129. cat.c               string handling functions for the parser
  2130. define.icn          macro definition program
  2131. ident.defs          macro definitions for the identity translator
  2132. usyms               macro names for unary operators
  2133. variant.c           parser functions for variant translators
  2134. variant.defs        macro definitions for the variant translator
  2135.  
  2136.  
  2137. h/config.h          Icon configuration parameters
  2138. h/cpuconf.h         processor configuration parameters
  2139. h/define.h          installation definitions
  2140. h/fdefs.h           Icon function definitions
  2141. h/keyword.h         keyword definitions
  2142. h/memsize.h         memory size parameters
  2143. h/odefs.h           Icon operator definitions
  2144. h/proto.h           function prototypes
  2145. h/rt.h              structures and definitions
  2146. h/version.h         version information
  2147.  
  2148.  
  2149. common/Makefile     Makefile for common area
  2150. common/cproto.h     function prototypes
  2151. common/getopt.c     routine to handle comman-line options
  2152.  
  2153.  
  2154.  
  2155.  
  2156.  
  2157.  
  2158.  
  2159.  
  2160.  
  2161.  
  2162.  
  2163.  
  2164.  
  2165.  
  2166.  
  2167.  
  2168.  
  2169.  
  2170.  
  2171.  
  2172.  
  2173.  
  2174.  
  2175.  
  2176.                              - 32 -
  2177.  
  2178.  
  2179.  
  2180.  
  2181.  
  2182.  
  2183.  
  2184.  
  2185. itran/Makefile      Makefile for itran area
  2186. itran/err.c         routines for producing error messages
  2187. itran/fixgram.icn   program to clean up grammar file after macro expansion
  2188. itran/general.h     general header declarations
  2189. itran/globals.h     global information
  2190. itran/icon_g.c      Yacc grammar for Icon before macro expansion
  2191. itran/lfile.h       link headers
  2192. itran/mktoktab.icn  program to build C functions for tokens and operators
  2193. itran/optab.txt     specifications for operator recognition
  2194. itran/pscript.ed    edit script to modify parser produced by Yacc
  2195. itran/sizes.h       translator sizing
  2196. itran/tlex.c        routines for lexical analysis
  2197. itran/tlex.h        structures and definitions used by the lexical analyzer
  2198. itran/tmem.c        memory initialization and management
  2199. itran/tokens.txt    token specifications
  2200. itran/trans.c       translator proper
  2201. itran/trans.h       external definitions used throughout the translator
  2202. itran/trash.icn     program to clean up Yacc output
  2203. itran/tree.c        routines to build tree structures
  2204. itran/tree.h        parse tree structures and accessing macros
  2205. itran/tsym.c        routines for symbol table management
  2206. itran/tsym.h        structures for symbol table entries
  2207. itran/util.c        utility functions
  2208. itran/vtmain.c      main program
  2209.  
  2210.  
  2211.  
  2212.  
  2213.  
  2214.  
  2215.  
  2216.  
  2217.  
  2218.  
  2219.  
  2220.  
  2221.  
  2222.  
  2223.  
  2224.  
  2225.  
  2226.  
  2227.  
  2228.  
  2229.  
  2230.  
  2231.  
  2232.  
  2233.  
  2234.  
  2235.  
  2236.  
  2237.  
  2238.  
  2239.  
  2240.  
  2241.  
  2242.                              - 33 -
  2243.  
  2244.  
  2245.  
  2246.  
  2247.  
  2248.  
  2249.  
  2250.  
  2251.              Appendix D - The Variant Translator Makefile
  2252.  
  2253.  
  2254.  
  2255. SHELL=/bin/sh
  2256. CFLAGS= -DVarTran
  2257. LDFLAGS=
  2258.  
  2259.  
  2260. OBJS=          cat.o err.o optab.o parse.o tlex.o tmem.o toktab.o trans.o \
  2261.                   tree.o tsym.o vtmain.o util.o variant.o
  2262.  
  2263.  
  2264.                $(CC) $(CFLAGS) $(LDFLAGS) -o ../vitran $(OBJS) \
  2265.                   ../common/getopt.o
  2266.  
  2267.  
  2268. $(OBJS):       ../h/config.h ../h/proto.h ../h/define.h
  2269.  
  2270.  
  2271. cat.o:         tree.h ../cat.c
  2272.                cc -c $(CFLAGS) ../cat.c
  2273.  
  2274.  
  2275. variant.o:     ../variant.c
  2276.                cc -c $(CFLAGS) ../variant.c
  2277.  
  2278. err.o:         trans.h tlex.h token.h tree.h
  2279. optab.o:       tlex.h
  2280. parse.o:       trans.h tsym.h tree.h ../h/keyword.h
  2281. tlex.o:        trans.h tlex.h token.h tree.h
  2282. tmem.o:        globals.h sizes.h trans.h tsym.h tree.h ../h/memsize.h
  2283. toktab.o:      trans.h tlex.h token.h
  2284. trans.o:       general.h globals.h sizes.h trans.h tsym.h token.h tree.h \
  2285.                ../h/version.h
  2286. tree.o:        tree.h
  2287. tsym.o:        globals.h sizes.h trans.h lfile.h tsym.h token.h
  2288. vtmain.o:      general.h globals.h
  2289. util.o:        general.h globals.h sizes.h link.h ../h/fdefs.h
  2290.  
  2291.  
  2292. parse.c token.h:expanded.g trash pscript.ed
  2293.                yacc -d expanded.g   # expect 218 shift/reduce conflicts
  2294.                ./trash <y.tab.c >parse.c
  2295.                ed - parse.c <pscript.ed
  2296.                mv y.tab.h token.h
  2297.  
  2298.  
  2299. expanded.g:    icon_g.c gdefs.h fixgram
  2300.                cc -E -C icon_g.c | ./fixgram >expanded.g
  2301.  
  2302.  
  2303.  
  2304.  
  2305.  
  2306.  
  2307.  
  2308.                              - 34 -
  2309.  
  2310.  
  2311.  
  2312.  
  2313.  
  2314.  
  2315.  
  2316.  
  2317. gdefs.h:       ../bsyms ../usyms ../ident.defs ../variant.defs
  2318.                cd ..;./define ident.defs variant.defs >gdefs.h
  2319.                mv ../gdefs.h .
  2320.  
  2321.  
  2322. toktab.c optab.c:tokens.txt optab.txt mktoktab
  2323.                ./mktoktab
  2324.  
  2325.  
  2326. trash:         trash.icn
  2327.                icont -s trash.icn
  2328.  
  2329.  
  2330. mktoktab:      mktoktab.icn
  2331.                icont -s mktoktab.icn
  2332.  
  2333.  
  2334. fixgram:       fixgram.icn
  2335.                icont -s fixgram.icn
  2336.  
  2337.  
  2338.  
  2339.  
  2340.  
  2341.  
  2342.  
  2343.  
  2344.  
  2345.  
  2346.  
  2347.  
  2348.  
  2349.  
  2350.  
  2351.  
  2352.  
  2353.  
  2354.  
  2355.  
  2356.  
  2357.  
  2358.  
  2359.  
  2360.  
  2361.  
  2362.  
  2363.  
  2364.  
  2365.  
  2366.  
  2367.  
  2368.  
  2369.  
  2370.  
  2371.  
  2372.  
  2373.  
  2374.                              - 35 -
  2375.  
  2376.  
  2377.